package cn.ht.jywrwater.module.ht.controller.admin.dataImport;

import cn.ht.jywrwater.framework.common.pojo.CommonResult;
import cn.ht.jywrwater.framework.excel.core.util.ExcelUtils;
import cn.ht.jywrwater.module.ht.controller.admin.dataImport.vo.*;
import cn.ht.jywrwater.module.ht.dal.mysql.statisticsdevicecount.StatisticsDeviceCountMapper;
import cn.ht.jywrwater.module.ht.dal.mysql.watercount.WaterCountMapper;
import cn.ht.jywrwater.module.ht.dal.mysql.waterqualityalertcount.WaterQualityAlertCountMapper;
import cn.ht.jywrwater.module.ht.service.dataimport.DataImportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

import static cn.ht.jywrwater.framework.common.pojo.CommonResult.success;

@Tag(name = "数据导入 - 数据导入")
@RestController
@RequestMapping("/ht/dataimport")
@Validated
public class DataImportController {


    @Resource
    private DataImportService dataImportService;


    @PostMapping("/import1")
    @Operation(summary = "导入村-设备")
    public CommonResult<Boolean> importExcel(@RequestParam("file") MultipartFile file) throws IOException {
        List<VillageDeviceImportExcelVO> list = ExcelUtils.read(file, VillageDeviceImportExcelVO.class);
        dataImportService.importVillageDeviceDatas(list);
        return success(true);
    }

    @PostMapping("/import2")
    @Operation(summary = "导入用户-设备")
    public CommonResult<Boolean> importExcel2(@RequestParam("file") MultipartFile file) throws IOException {
        List<CustomerDeviceImportExcelVO> list = ExcelUtils.read(file, CustomerDeviceImportExcelVO.class);
        dataImportService.importCustomerDeviceDatas(list);
        return success(true);
    }


    @PostMapping("/import-town")
    @Operation(summary = "乡镇数据导入")
    public CommonResult<Boolean> importExcelTown(@RequestParam("file") MultipartFile file) throws IOException {
        List<TownImportExcelVO> list = ExcelUtils.read(file, TownImportExcelVO.class);
        dataImportService.importTowns(list);
        return success(true);
    }

    @PostMapping("/import-water-quality-factor")
    @Operation(summary = "水质因子数据导入")
    public CommonResult<Boolean> importExcelFactor(@RequestParam("file") MultipartFile file) throws IOException {
        List<WaterQualityFactorImportExcelVO> list = ExcelUtils.read(file, WaterQualityFactorImportExcelVO.class);
        dataImportService.importWaterQualityFactor(list);
        return success(true);
    }

    @PostMapping("/import-water-quality-data")
    @Operation(summary = "水质数据导入")
    public CommonResult<Boolean> importExcelWaterQualityData(@RequestParam("file") MultipartFile file) throws IOException {
        List<WaterQualityDataImportExcelVO> list = ExcelUtils.read(file, WaterQualityDataImportExcelVO.class);
        dataImportService.importWaterQualityData(list);
        return success(true);
    }

    @PostMapping("/import-water-quality-device-data")
    @Operation(summary = "水质设备数据导入")
    public CommonResult<Boolean> importExcelWaterQualityDevice(@RequestParam("file") MultipartFile file) throws IOException {
        List<WaterQualityDeviceImportExcelVO> list = ExcelUtils.read(file, WaterQualityDeviceImportExcelVO.class);
        dataImportService.importWaterQualityDevice(list);
        return success(true);
    }


}
